package com.shengyin.ec.model.dao.alliance;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.shengyin.ec.model.dao.BaseDaoImpl;
import com.shengyin.ec.model.entity.Company;
import com.shengyin.ec.model.entity.Personal;

@Repository("allianceDao")
public class AllianceDaoImpl extends BaseDaoImpl<Company> implements AllianceDao {

	/*
	 * ����δ�����ҵ
	 * */
	public List<Company> getCompanyVerifyNot(){
		List<Company> list  = super.find("From Company c where c.status=0");
		return list;
	}
	
	/*
	 * �����������ҵ
	 * */
	public List<Company> getCompanyOfverifyed(){
		List<Company> list  =super.find("From Company c where c.status=1");
		return list;
	}
	
	/*
	 * ������˲�ͨ����ҵ
	 * */
	public List<Company> getCompanyVerifyFail(){
		List<Company> list  = super.find("From Company c where c.status=2");
		return list;
	}
	
	public List<Company> getCompanyList(int status){
		
		List<Company> list  = super.find("From Company c where c.status="+status);
		return list;
	}
	/*
	 * ����Ա�����ҵ
	 * */
	public List<Company> verifyCompany(int status){
		List<Company> list  =super.find("From Company c where c.status="+status);
		return list;
	}
	
	//add by lcl 2012-3-29
	public boolean checkCompanyUser(String username, String pwd){
		try {
			ArrayList<Company> list = (ArrayList<Company>) super.find("From Company c where  c.username='"+username+"' and c.pwd='"+pwd+"'");
			if(list.size()==0)
			   return false;
			else
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public List<Company> getCompanyByName(String username){
		List<Company> list = (List<Company>)super.find("From Company c where c.username='"+username+"'");
		return list;
	}
	
	//add by wql 2012-3-20
		public List<Company> getCompanyList(int offset,int pagesize){
			return super.findByPage("from Company company where companyType='1'", offset, pagesize);
		}
		
		public List<Company> getCompany(int status,int offset,int pagesize){
			return super.findByPage("from Company company where companyType='1'and company.status =' "+status+"'", offset, pagesize);
		}

		public Long getTotal(){
			return (Long)super.find("select count(*) from Company where companyType='1'").get(0);
		}
		
		@Override
		public void deleteSelectedAlliance(Long[] ids) {
			Company company=null;
			List<Company> companyList=new ArrayList<Company>(0);
			for(long id:ids)
			{
				company=super.get(id);
				companyList.add(company);
			}
			super.deleteAll(companyList);
			
		}
		@Override
		public void updateAlliance(Company company){
			super.update(company);
		}
		
		public List<Company> getCompanyListByCity(){
			List<Company> list  = super.find("From Company where companyType=0 order by companyarea");
			return list;
		}
		public List<Company> getCompanyListByNature(){
			List<Company> list  = super.find("From Company where companyType=0 order by nature");
			return list;
		}
		public List<Company> getCompanyListByEmployee(){
			List<Company> list  = super.find("From Company where companyType=0 order by employees");
			return list;
		}
		
		public List<Company> getAllianceCompanyList(){
			List<Company> list  = super.find("From Company where companyType=0");
			return list;
		}
		
		public List<Company> getCompanyListByName(String keyword,int offset,int pageSize){
			
			return super.findByPage("from Company where companyType='1' and companyname like ?", keyword, offset, pageSize);
		}
		public List<Company> getCompanyListByName(String keyword){
			
			String[] values = new String[2];
			values[0]="2";
			values[1]=keyword;
			return super.find("from Company where companyType=? and companyname= ?", values);
		}
}
